﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.TcCommands.TcCheckoutCheckin.PrivateImplementationDetails.CApTcCIOUtil
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Planning;


namespace DnProcessSimulateCommands.TcCommands.TcCheckoutCheckin.PrivateImplementationDetails;

public class CApTcCIOUtil
{
  internal static ITxPlanningObject GetPlanningObject(ITxObject obj)
  {
    switch (obj)
    {
      case ITxProcessModelObject processModelObject:
        pattern_0 = processModelObject.PlanningRepresentation;
        break;
    }
    return pattern_0;
  }

  internal static TxPlanningTypeMetaData GetTypeMetaData(ITxObject obj)
  {
    TxPlanningTypeMetaData typeMetaData = (TxPlanningTypeMetaData) null;
    ITxPlatformGlobalServicesProvider servicesProvider = TxApplication.ActiveDocument.PlatformGlobalServicesProvider;
    if (servicesProvider != null)
    {
      ITxPlanningObject planningObject = CApTcCIOUtil.GetPlanningObject(obj);
      if (planningObject != null)
        typeMetaData = servicesProvider.GetTypeMetaData(planningObject.PlanningType);
    }
    return typeMetaData;
  }

  internal static bool IsStudyRoot(ITxObject obj)
  {
    bool flag = false;
    if (obj is TxPhysicalRoot)
    {
      ITxObject byProcessModelId = TxApplication.ActiveDocument.GetObjectByProcessModelId(TxTcUtilities.GetPrimaryRoot());
      if (obj == byProcessModelId)
        flag = true;
    }
    return flag;
  }

  internal static bool IsValidOperationOrStudy(ITxObject obj)
  {
    int num;
    switch (obj)
    {
      case ITxTcOperation _:
      case TxTcProcess _:
        num = 1;
        break;
      default:
        num = CApTcCIOUtil.IsStudyRoot(obj) ? 1 : 0;
        break;
    }
    return num != 0;
  }

  internal static bool IsValidResource(ITxObject obj)
  {
    bool flag = false;
    TxPlanningTypeMetaData typeMetaData = CApTcCIOUtil.GetTypeMetaData(obj);
    if (typeMetaData != null)
    {
      flag = typeMetaData.IsDerivedFromPlanningType("Mfg0MEResourceRevision") || typeMetaData.IsDerivedFromPlanningType("MEWorkareaRevision");
      if (!flag)
      {
        flag = typeMetaData.IsDerivedFromPlanningType("ItemRevision");
        if (flag)
        {
          flag = TxEngineeringDataInternal.ObjectIsResourceInstance(obj);
          if (!flag)
            flag = obj is TxCompoundResource;
        }
      }
    }
    return flag;
  }

  internal static TxObjectList ExtractEditableObjects(TxObjectList selectedObjects)
  {
    TxObjectList editableObjects = new TxObjectList();
    foreach (ITxObject selectedObject in (Collection<ITxObject>) selectedObjects)
    {
      if (!TxIconManager.ObjectNeedsLockOverlay(selectedObject))
        ((Collection<ITxObject>) editableObjects).Add(selectedObject);
    }
    return editableObjects;
  }

  public static TxObjectList GetObjectsWithBomLineUid(TxObjectList objects)
  {
    TxObjectList objectsWithBomLineUid = new TxObjectList();
    TxObjectList planningRepresentations = ((TxObjectList<ITxObject>) objects).PlanningRepresentations;
    if (planningRepresentations != null && ((Collection<ITxObject>) planningRepresentations).Count > 0)
    {
      TxObjectList<ITxPlanningObject> txObjectList = new TxObjectList<ITxPlanningObject>(((IEnumerable) planningRepresentations).Cast<ITxPlanningObject>());
      try
      {
        Dictionary<ITxPlanningObject, string> byPlanningObjects = TxTcUtilities.GetBomLineUidsByPlanningObjects(txObjectList);
        if (byPlanningObjects != null)
        {
          if (byPlanningObjects.Count == ((Collection<ITxObject>) objects).Count)
          {
            int index = 0;
            foreach (KeyValuePair<ITxPlanningObject, string> keyValuePair in byPlanningObjects)
            {
              if (!string.IsNullOrEmpty(keyValuePair.Value))
                ((Collection<ITxObject>) objectsWithBomLineUid).Add(((Collection<ITxObject>) objects)[index]);
              ++index;
            }
          }
        }
      }
      catch
      {
      }
    }
    return objectsWithBomLineUid;
  }

  public static bool IsCurrentTcVersionCompatible(string commandName)
  {
    bool flag = true;
    if (TxTcSessionInfoEx.IsServerVersionLowerThan("11.2.5.2017081500"))
    {
      flag = false;
      int num = (int) TxMessageBox.ShowModal(DnProcessSimulateCommands.TcCommands.TcCheckoutCheckin.StringTable.TC_CHECKOUTCHECKIN_REQUIRED_TC_VERSION, commandName, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
    }
    return flag;
  }
}
